<?php

/**
 * digSearch page
 * 
 * This controller class was generated with Digitalus Framework Developer Tools
 * 
 * @author developer
 */
class DigSearch_PageController extends DigCms_Library_Item_Controller
{

    /**
     * Renders the page content type.
     */
    public function renderAction()
    {
        $query = $this->getRequest()->getParam('query', null);
        $category = $this->getRequest()->getParam('category', null);
        $page = $this->getRequest()->getParam('page', 1);
        $cache = Dig_Service_Core::getParam('cache');
        $cacheKey = 'searchResults' . zend_filter::filterStatic($query . $category, 'Alnum');
        if((! $paginator = $cache->load($cacheKey)) && (! empty($query))) {
            $results = DigSearch_Service_Index::keywordSearch($query, $category);
            if($results) {
                $paginator = Zend_Paginator::factory($results);
                $cache->save($paginator, $cacheKey, array('search_engine'));
            }
        }
        if($paginator) {
            $paginator->setCurrentPageNumber($page);
            $paginator->setItemCountPerPage($this->_model->result_count);
            $this->view->paginator = $paginator;
        }
        $this->view->category = $category;
        $this->view->query = $query;
    }


}

